package com.zzxx.wechat.config;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.stereotype.Component;


@Component
public class CommonConfig {

    private final ThreadFactory defaultThreadFactory = new CustomizableThreadFactory("common-ThreadPool-");

    private final ThreadFactory parallelProductThreadFactory = new CustomizableThreadFactory("common-Parallel-Product-");

    @Bean(name = "arcteryxLinkQueryExector")
    public ThreadPoolExecutor arcteryxLinkQueryExector() {
        return new ThreadPoolExecutor(50,
                50, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10),
                defaultThreadFactory, new CallerRunsPolicy());
    }



    @Bean(name = "arcteryxParallelProcessingExecutor")
    public ThreadPoolExecutor arcteryxParallelProcessingExecutor() {
        return new ThreadPoolExecutor(50,
                100, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10),
                parallelProductThreadFactory, new CallerRunsPolicy());
    }
    @Bean(name = "arcteryxJobExecutor")
    public ThreadPoolExecutor arcteryxJobExecutor() {
        return new ThreadPoolExecutor(10,
                10, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100),
                parallelProductThreadFactory, new CallerRunsPolicy());
    }



}
